package com.yanqu.road.entity.player;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class UserBeauty extends DataObject {

    private long userId;

    private int beautyId;
    /**
     * 亲密度
     */
    private int intimacy;
    /**
     * 魅力值
     */
    private int glamour;
    /**
     * 弃用保留
     * 美女等级
     */
    private int level;
    /**
     * 美女门客技能1等级
     */
    private int skill1;
    /**
     * 美女门客技能2等级
     */
    private int skill2;
    /**
     * 美女门客技能升级经验，由原先缘分值改每个美女独有
     */
    private long skillExp;
    /**
     * 当前美名等级
     */
    private int identityLv;
    /**
     * 子嗣数量
     */
    private int childCount;
    /**
     * 累计传唤次数
     */
    private int totalTrystTimes;
    /**
     * 累计赏赐次数
     */
    private int totalRewardTimes;
    /**
     * 当前美名技能等级
     */
    private int identitySkillLv;
    /**
     * 客户端是否展示过
     */
    private boolean isShow;

    /**
     * 皮肤id
     */
    private int skinId;

    /**
     * 皮肤增加的亲密度
     */
    private int skinIntimacy;

    /**
     * 皮肤增加的魅力
     */
    private int skinGlamour;

    private long createTime;

    private int travelTimes;

    private int bathTimes;

    private int quality;        //品质

    private int qualityPromotionId;   //品质晋升id

    private long escortExp;     //押镖经验

    private int escortSkill1;    //押镖技能等级（门客赚钱固定值）

    private int escortSkill2;   //押镖技能等级（门客资质固定值）

    private int skinSkill1;     //皮肤技能1
    private int skinSkill2;     //皮肤技能2

    private int promotionSkill; // 美女晋升技能,为了兼容这个定死了是第一个孔的升级需求技能

    private List<Integer> promoteSkillList = new ArrayList<>();// 道具无双的第二个孔以及之后的缘定三生技能

    /**
     * 无双技能
     */
    private Map<Integer, BeautyPeerlessSkillInfo> peerlessSkillMap = new ConcurrentHashMap<>();
    private int peerlessUp;    //无双晋升次数

    private int guessTimes;// 可猜谜次数(不用入库)
    private int poetryTimes;// 可吟诗次数(不用入库)
    private int genderSwapMark;     //切换标识

    private int curioGlamour;      //藏品增加的魅力值/才华
    private int curioIntimacy;     //藏品增加的亲密度/友好

    private int travelBookIntimacy; // 旅行册增加的亲密度/友好
    private int travelBookGlamour; // 旅行册增加的魅力值/才华

    private Map<Integer, UserBeautySkill> skillMap = new ConcurrentHashMap<>();

    /**
     * 妙音坊美名技能等级
     */
    private Property musicRoomSkill = new Property();

    /**
     * 旅行册卡册技能等级
     */
    private Map<Integer, Integer> albumSkillMap = new ConcurrentHashMap<>();

    /**
     * 美女自选缘分门客，K:空位ID,V:门客信息
     */
    private Map<Integer, BeautySelfSelectPatronsPosition> selfSelectPatronsMap = new ConcurrentHashMap<>();

    private BigDecimal totalRelationPatronsAbility = BigDecimal.ZERO; //美女给所有缘分门客加的赚钱总和

    private Set<Integer> oriRelationPatronsId = new HashSet<>();//原始的缘分门客缓存,不入库

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if(this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public int getBeautyId() {
        return beautyId;
    }

    public void setBeautyId(int beautyId) {
        if(this.beautyId != beautyId) {
            this.beautyId = beautyId;
            setUpdateOption();
        }
    }

    public int getIntimacy() {
        return intimacy;
    }

    public void setIntimacy(int intimacy) {
        if(this.intimacy != intimacy) {
            this.intimacy = intimacy;
            setUpdateOption();
        }
    }

    public int getGlamour() {
        return glamour;
    }

    public void setGlamour(int glamour) {
        if(this.glamour != glamour) {
            this.glamour = glamour;
            setUpdateOption();
        }
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        if(this.level != level) {
            this.level = level;
            setUpdateOption();
        }
    }

    public int getSkill1() {
        return skill1;
    }

    public void setSkill1(int skill1) {
        if(this.skill1 != skill1) {
            this.skill1 = skill1;
            setUpdateOption();
        }
    }

    public int getSkill2() {
        return skill2;
    }

    public void setSkill2(int skill2) {
        if(this.skill2 != skill2) {
            this.skill2 = skill2;
            setUpdateOption();
        }
    }

    public long getSkillExp() {
        return skillExp;
    }

    public void setSkillExp(long skillExp) {
        if(this.skillExp != skillExp) {
            this.skillExp = skillExp;
            setUpdateOption();
        }
    }

    public int getIdentityLv() {
        return identityLv;
    }

    public void setIdentityLv(int identityLv) {
        if(this.identityLv != identityLv) {
            this.identityLv = identityLv;
            setUpdateOption();
        }
    }

    public int getChildCount() {
        return childCount;
    }

    public void setChildCount(int childCount) {
        if(this.childCount != childCount) {
            this.childCount = childCount;
            setUpdateOption();
        }
    }

    public int getTotalTrystTimes() {
        return totalTrystTimes;
    }

    public void setTotalTrystTimes(int totalTrystTimes) {
        if(this.totalTrystTimes != totalTrystTimes) {
            this.totalTrystTimes = totalTrystTimes;
            setUpdateOption();
        }
    }

    public int getTotalRewardTimes() {
        return totalRewardTimes;
    }

    public void setTotalRewardTimes(int totalRewardTimes) {
        if(this.totalRewardTimes != totalRewardTimes) {
            this.totalRewardTimes = totalRewardTimes;
            setUpdateOption();
        }
    }

    public int getIdentitySkillLv() {
        return identitySkillLv;
    }

    public void setIdentitySkillLv(int identitySkillLv) {
        if(this.identitySkillLv != identitySkillLv) {
            this.identitySkillLv = identitySkillLv;
            setUpdateOption();
        }
    }

    public boolean isShow() {
        return isShow;
    }

    public void setShow(boolean show) {
        if(this.isShow != show) {
            isShow = show;
            setUpdateOption();
        }
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        if(this.createTime != createTime) {
            this.createTime = createTime;
            setUpdateOption();
        }
    }

    public void setSkillMap(Map<Integer, UserBeautySkill> skillMap) {
        this.skillMap = skillMap;
    }

    public Map<Integer, UserBeautySkill> getSkillMap() {
        return skillMap;
    }

    public boolean hasBeautySkill(int skillPos){
        return skillMap.containsKey(skillPos);
    }

    public void addBeautySkill(int skillPos, UserBeautySkill beautySkill){
        if(!hasBeautySkill(skillPos)) {
            skillMap.put(skillPos, beautySkill);
        }
    }

    public int getMaxSkillPos(){
        if(null != skillMap){
            int maxPos = 0;
            for(UserBeautySkill beautySkill : skillMap.values()){
                if(beautySkill.getSkillPos() > maxPos){
                    maxPos = beautySkill.getSkillPos();
                }
            }
            return maxPos;
        }
        return 0;
    }

    public int getTravelTimes() {
        return travelTimes;
    }

    public void setTravelTimes(int travelTimes) {
        if(this.travelTimes != travelTimes) {
            this.travelTimes = travelTimes;
            setUpdateOption();
        }
    }

    public int getBathTimes() {
        return bathTimes;
    }

    public void setBathTimes(int bathTimes) {
        if(this.bathTimes != bathTimes) {
            this.bathTimes = bathTimes;
            setUpdateOption();
        }
    }

    public int getSkinId() {
        return skinId;
    }

    public void setSkinId(int skinId) {
        if (this.skinId != skinId) {
            this.skinId = skinId;
            setUpdateOption();
        }
    }

    public int getSkinIntimacy() {
        return skinIntimacy;
    }

    public void setSkinIntimacy(int skinIntimacy) {
        if (this.skinIntimacy != skinIntimacy) {
            this.skinIntimacy = skinIntimacy;
            setUpdateOption();
        }
    }

    public int getSkinGlamour() {
        return skinGlamour;
    }

    public void setSkinGlamour(int skinGlamour) {
        if (this.skinGlamour != skinGlamour) {
            this.skinGlamour = skinGlamour;
            setUpdateOption();
        }
    }

    public int getQuality() {
        return quality;
    }

    public void setQuality(int quality) {
        if(this.quality != quality) {
            this.quality = quality;
            setUpdateOption();
        }
    }

    public int getQualityPromotionId() {
        return qualityPromotionId;
    }

    public void setQualityPromotionId(int qualityPromotionId) {
        if(this.qualityPromotionId != qualityPromotionId) {
            this.qualityPromotionId = qualityPromotionId;
            setUpdateOption();
        }
    }

    public int getTotalIntimacy() {
        return intimacy + skinIntimacy + curioIntimacy + travelBookIntimacy;
    }

    public int getTotalGlamour() {
        return glamour + skinGlamour + curioGlamour + travelBookGlamour;
    }

    public long getEscortExp() {
        return escortExp;
    }

    public void setEscortExp(long escortExp) {
        if(this.escortExp != escortExp) {
            this.escortExp = escortExp;
            setUpdateOption();
        }
    }

    public int getEscortSkill1() {
        return escortSkill1;
    }

    public void setEscortSkill1(int escortSkill1) {
        if(this.escortSkill1 != escortSkill1) {
            this.escortSkill1 = escortSkill1;
            setUpdateOption();
        }
    }

    public int getEscortSkill2() {
        return escortSkill2;
    }

    public void setEscortSkill2(int escortSkill2) {
        if(this.escortSkill2 != escortSkill2) {
            this.escortSkill2 = escortSkill2;
            setUpdateOption();
        }
    }

    public int getSkinSkill1() {
        return skinSkill1;
    }

    public void setSkinSkill1(int skinSkill1) {
        if(this.skinSkill1 != skinSkill1) {
            this.skinSkill1 = skinSkill1;
            setUpdateOption();
        }
    }

    public int getSkinSkill2() {
        return skinSkill2;
    }

    public void setSkinSkill2(int skinSkill2) {
        if(this.skinSkill2 != skinSkill2) {
            this.skinSkill2 = skinSkill2;
            setUpdateOption();
        }
    }

    public int getPromotionSkill() {
        return promotionSkill;
    }

    public void setPromotionSkill(int promotionSkill) {
        if(this.promotionSkill != promotionSkill) {
            this.promotionSkill = promotionSkill;
            setUpdateOption();
        }
    }

    public int getGuessTimes() {
        return guessTimes;
    }

    public void setGuessTimes(int guessTimes) {
        this.guessTimes = guessTimes;
    }

    public int getPoetryTimes() {
        return poetryTimes;
    }

    public void setPoetryTimes(int poetryTimes) {
        this.poetryTimes = poetryTimes;
    }

    public Map<Integer, BeautyPeerlessSkillInfo> getPeerlessSkillMap() {
        return peerlessSkillMap;
    }

    public void setPeerlessSkillMap(Map<Integer, BeautyPeerlessSkillInfo> peerlessSkillMap) {
        this.peerlessSkillMap = peerlessSkillMap;
    }

    public int getPeerlessSkillLevelByPatronsId(int patronsId) {
        for (BeautyPeerlessSkillInfo peerlessSkillInfo : this.peerlessSkillMap.values()) {
            if (peerlessSkillInfo.getPatronsId() == patronsId) {
                return peerlessSkillInfo.getLevel();
            }
        }
        return 0;
    }

    public void addPeerlessSkillLevelIfNull(int id) {
        BeautyPeerlessSkillInfo skillInfo = this.peerlessSkillMap.get(id);
        if (null == skillInfo) {
            skillInfo = new BeautyPeerlessSkillInfo();
            skillInfo.setId(id);
            skillInfo.setPatronsId(0);
            skillInfo.setLevel(1);//初始1级
            this.peerlessSkillMap.put(id, skillInfo);
            setUpdateOption();
        }
    }

    public void updatePeerlessSkillLevel(int id, int level) {
        BeautyPeerlessSkillInfo skillInfo = this.peerlessSkillMap.get(id);
        if (null == skillInfo) {
            skillInfo = new BeautyPeerlessSkillInfo();
            skillInfo.setId(id);
            this.peerlessSkillMap.put(id, skillInfo);
        }
        skillInfo.setLevel(level);

        setUpdateOption();
    }

    public BeautyPeerlessSkillInfo getPeerlessSkill(int id) {
        return this.peerlessSkillMap.get(id);
    }

    public int getPeerlessUp() {
        return peerlessUp;
    }

    public void setPeerlessUp(int peerlessUp) {
        this.peerlessUp = peerlessUp;
        if (this.peerlessUp != peerlessUp) {
            this.peerlessUp = peerlessUp;
            setUpdateOption();
        }
    }

    public int getGenderSwapMark() {
        return genderSwapMark;
    }

    public void setGenderSwapMark(int genderSwapMark) {
        if(this.genderSwapMark != genderSwapMark) {
            this.genderSwapMark = genderSwapMark;
            setUpdateOption();
        }
    }

    public Property getMusicRoomSkill() {
        return musicRoomSkill;
    }

    public void setMusicRoomSkill(Property musicRoomSkill) {
        this.musicRoomSkill = musicRoomSkill;
        setUpdateOption();
    }

    public int getMusicRoomSkillLevel(int skillId) {
        return musicRoomSkill.getCountByGoodsId(skillId).intValue();
    }

    public void addMusicRoomSkillLevel(int skillId, int addLevel) {
        musicRoomSkill.addProperty(skillId, addLevel);
        setUpdateOption();
    }

    public void setMusicRoomSkillLevel(int skillId, int level) {
        if (level == 0) {
            musicRoomSkill.removeProperty(skillId);
        } else {
            musicRoomSkill.setGood(skillId, BigInteger.valueOf(level));
        }
        setUpdateOption();
    }

    public int getCurioGlamour() {
        return curioGlamour;
    }

    public void setCurioGlamour(int curioGlamour) {
        if(this.curioGlamour != curioGlamour) {
            this.curioGlamour = curioGlamour;
            setUpdateOption();
        }
    }

    public int getCurioIntimacy() {
        return curioIntimacy;
    }

    public void setCurioIntimacy(int curioIntimacy) {
        if (this.curioIntimacy != curioIntimacy) {
            this.curioIntimacy = curioIntimacy;
            setUpdateOption();
        }
    }

    public int getTravelBookIntimacy() {
        return travelBookIntimacy;
    }

    public void setTravelBookIntimacy(int travelBookIntimacy) {
        if (this.travelBookIntimacy != travelBookIntimacy) {
            this.travelBookIntimacy = travelBookIntimacy;
            setUpdateOption();
        }
    }

    public int getTravelBookGlamour() {
        return travelBookGlamour;
    }

    public void setTravelBookGlamour(int travelBookGlamour) {
        if (this.travelBookGlamour != travelBookGlamour) {
            this.travelBookGlamour = travelBookGlamour;
            setUpdateOption();
        }
    }

    public Map<Integer, BeautySelfSelectPatronsPosition> getSelfSelectPatronsMap() {
        return selfSelectPatronsMap;
    }

    public void setSelfSelectPatronsMap(Map<Integer, BeautySelfSelectPatronsPosition> selfSelectPatronsMap) {
        this.selfSelectPatronsMap = selfSelectPatronsMap;
    }

    public void putSelfSelectPatrons(BeautySelfSelectPatronsPosition patronsPosition) {
        this.selfSelectPatronsMap.put(patronsPosition.getId(), patronsPosition);
        setUpdateOption();
    }

    public BigDecimal getTotalRelationPatronsAbility() {
        return totalRelationPatronsAbility;
    }

    public void setTotalRelationPatronsAbility(BigDecimal totalRelationPatronsAbility) {
        this.totalRelationPatronsAbility = totalRelationPatronsAbility;
    }

    public Set<Integer> getOriRelationPatronsId() {
        return oriRelationPatronsId;
    }

    public void setOriRelationPatronsId(Set<Integer> oriRelationPatronsId) {
        this.oriRelationPatronsId = oriRelationPatronsId;
    }

    public List<Integer> getPromoteSkillList() {
        return promoteSkillList;
    }

    public void setPromoteSkillList(List<Integer> promoteSkillList) {
        this.promoteSkillList = promoteSkillList;
        setUpdateOption();
    }

    public int getPromoteSkillLevelByPos(int pos) {
        if (pos <= 0) {
            return 0;
        }
        if (pos == 1) {
            return getPromotionSkill();
        }

        int idx = pos - 2;
        if (idx < 0 || idx >= this.promoteSkillList.size()) {
            return 0;
        }
        return this.promoteSkillList.get(idx);
    }

    public void setPromoteSkillLevelByPos(int pos, int level) {
        if (pos <= 0) {
            return;
        }
        if (pos == 1) {
            setPromotionSkill(level);
            return;
        }
        int idx = pos - 2;
        if (idx >= this.promoteSkillList.size()) {
            int size = idx - this.promoteSkillList.size() + 1;
            for (int i = 0; i < size; i++) {
                this.promoteSkillList.add(0);
            }
        }

        this.promoteSkillList.set(idx, level);

        setUpdateOption();
    }

    public Map<Integer, Integer> getAlbumSkillMap() {
        return albumSkillMap;
    }

    public String getAlbumSkillMapStr() {
        Property tmp = new Property();

        for (Map.Entry<Integer, Integer> kv : albumSkillMap.entrySet()) {
            tmp.addProperty(kv.getKey(), kv.getValue());
        }

        return PropertyHelper.parsePropertyToString(tmp);
    }

    public void setAlbumSkillMap(Map<Integer, Integer> albumSkillMap) {
        if (albumSkillMap != null && this.albumSkillMap != albumSkillMap) {
            this.albumSkillMap = albumSkillMap;
        }
    }

    public void albumSkillLevelUp(int skillId, int level) {
        albumSkillMap.merge(skillId, level, Integer::sum);
        setUpdateOption();
    }
}
